<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv ="proma" content = "no-cache"/>
<meta http-equiv="cache-control" content="no cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>学生-班级-任务</title>
<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/classTask-stu.css'/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<script src="<c:url value='/js/classTaskStu.js'/>" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<%@include file="/common/header.jsp"%>
	<%@include file="classHeader.jsp"%>
	<div class="container-fluid main">
		<div class="row">
			<div class="col-xs-12 col-sm-12 col-md-9">
				<%@include file="classNav.jsp"%>
				<!-- 任务列表 -->
				<div id="task-list">
					<div class="row">
						
						<div class="col-md-12">
							
							<!-- 个人任务 && 其他四类任务 -->
							<div class="task-classify">
								<div class="task-classify-title">
									<ul>
										<li class="other-task" id="other-href" >课堂任务</li>
										<li class="personal-task" id="personal-href" >个人任务</li>
									</ul>
								</div>
							</div>
						</div>
						<div class="task-status-infor col-md-12">
							<div class="infor infor-h"><div class="infor-d infor-hd"></div>已批改</div>
							<div class="infor infor-r"><div class="infor-d infor-rd"></div>已提交</div>
							<div class="infor infor-n"><div class="infor-d infor-nd"></div>未提交</div>
						</div>					
						<!-- 个人任务列表 -->
						<div class="col-md-12" id="personal-task-list">
							<table class="table table-hover" id="table-pc">
								<thead>
									<tr>
										<th>任务名</th>
										<th>分配时间</th>
										<th>发布者</th>
										<th>
											<select class="form-control" id="searchTaskStatus" onchange="taskStatusSearch()">
												<option value="ALL" selected = "selected">全部</option>
												<option value="COMMITTED">已提交</option>
												<option value="UNCOMMITTED">未提交</option>
												<option value="HAVEREAD">已批改</option>
											</select>
										</th>
										
									</tr>
								</thead>
								<tbody id="taskList-personal">
									
								</tbody>
							</table>

							<table class="table table-hover" id="table-mobile">
								<thead>
									<tr>
										<th>任务名</th>
										<th>分配时间</th>
									</tr>
								</thead>
								<tbody id="taskList-personal1">
									
								</tbody>
							</table>
						</div>
						
						
						<!-- 其他四类任务列表 -->
						<div class="col-md-12" id="other-task-list">
							<table class="table table-hover" id="other-table-pc">
								<thead>
									<tr>
										<th>
											<select class="form-control" id="searchTaskType"  onchange="taskTypeSearch()">
												<option selected = "selected" value="ALL">全部</option>
												<option value="ASKINLESSON">课堂提问</option>
												<option value="TESTINLESSON">当堂测试</option>
												<option value="HOMEWORK">课后作业</option>
												<option value="LABTEST">实验任务</option>													
											</select>
										</th>
										<th>任务名</th>
										<th>截止时间</th>
										<th>状态</th>
										<th>课堂</th>
										
									</tr>
								</thead>
								<tbody id="taskList">
									
								</tbody>
							</table>
							
							<table class="table table-hover" id="other-table-mobile">
								<thead>
									<tr>
										<th>任务名</th>
										<th>截止时间</th>
									</tr>
								</thead>
								<tbody id="taskList1">
									
								</tbody>
							</table>
							
						</div>
						<!-- 分页 -->
						<div class="page-content" id="taskPage">
							<nav class="pagination" role="navigation">
								<a class="last-page" href="#">
									<i class="fa fa-angle-left"></i>
								</a>
								<span class="page-number">...</span>
								<a class="next-page" href="#">
									<i class="fa fa-angle-right"></i>
								</a>
							</nav>
						</div>
					</div>
				</div>
				<!-- 任务详情 -->
				<div id="task-detail">
					<!-- 任务信息 -->
					<div class="col-md-12">
						<%@include file="taskDetail.jsp"%>
					</div>
				</div>
			</div>
			
			<!--教师、助教信息，课程简介-->
			<div class="col-xs-12 col-md-3">
				<%@include file="classRight.jsp"%>
			</div>
		</div>
	</div>
	<%@include file="/common/footer.jsp"%>
</body>
<script>
var data=${data};
$(document).ready(function() {
	if (data.status != "success") {
		alert(data.message);
		return;
	};
	$("#task").css("color","#00b43c");
	$("#personal-href").click(function() {
		window.location.href=CONTEXT_PATH + "taskListStuView/taskPersonal?classId=" + data.data.classView.classId;
		$("#personal-href").css("color","#00b43c");
	});
	$("#other-href").click(function() {
		window.location.href=CONTEXT_PATH + "taskListStuView/taskList?classId=" + data.data.classView.classId;
		$("#other-href").css("color","#00b43c");
	});
	initClassView(data.data.classView);
	if(data.data.type=="PERSONALTASK"){
		personalVisible();
		initPersonalTask(data.data);
	}else if(data.data.type=="TASKMAIN"){
		taskVisible();
		initLessonTask(data.data);
	}
	
});
var initPages = function(pageNo,allpages){
	var classId = ${param.classId};
	var lastPageObj=$("#taskPage .last-page");
	var nextPageObj=$("#taskPage .next-page");
	var pageNumberObj=$("#taskPage .page-number");
	var taskType=$("#searchTaskType  option:selected").val();
	var lastPage=pageNo-1;
	if(lastPage<=0){//设置disableed
		lastPage=1;
		lastPageObj.removeAttr("href");
	}else{//taskListStuView/taskPersonal
		if(data.data.type=="PERSONALTASK"){
			lastPageObj.attr("href","<c:url value='/taskListStuView/taskPersonal?classId="+classId+"&pageNo="+lastPage+"&type="+taskType+"'/>");
		}else{
			lastPageObj.attr("href","<c:url value='/taskListStuView/taskList?classId="+classId+"&pageNo="+lastPage+"&type="+taskType+"'/>");
		}
	}
	var nextPage = pageNo+1;
	if(nextPage>allpages){
		nextPage=allpages;
		nextPageObj.removeAttr("href");
	}else{
		if(data.data.type=="PERSONALTASK"){
			nextPageObj.attr("href","<c:url value='/taskListStuView/taskPersonal?classId="+classId+"&pageNo="+nextPage+"&type="+taskType+"'/>");
		}else{
			nextPageObj.attr("href","<c:url value='/taskListStuView/taskList?classId="+classId+"&pageNo="+nextPage+"&type="+taskType+"'/>");
		}
	}
	/* 需要进一步改进上下这块 */
	if(allpages <= 1){
		$("#taskPage").hide();
	}else{
		pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
		$("#taskPage").show();
	}
	
};
var taskTypeSearch = function(){
	var classId = ${param.classId};
	var taskType=$("#searchTaskType  option:selected").val();
	if(taskType=="ALL"){
		window.location.href="<c:url value='/taskListStuView/taskList?classId="+classId+"'/>";
	}else{
		window.location.href="<c:url value='/taskListStuView/taskList?classId="+classId+"&type="+taskType+"'/>";
	}
}

var taskStatusSearch = function(){
	var classId = ${param.classId};
	var taskType=$("#searchTaskStatus  option:selected").val();
	if(taskType=="ALL"){
		window.location.href="<c:url value='/taskListStuView/taskPersonal?classId="+classId+"'/>";
	}else{
		window.location.href="<c:url value='/taskListStuView/taskPersonal?classId="+classId+"&taskStatus="+taskType+"'/>";
	}
}
var initPersonalTask = function(data){
	var taskStatus='${param.taskStatus}';
	if(!isEmpty(taskStatus)){
		$("#searchTaskStatus").val(taskStatus);
	}
	var personalList=$("#taskList-personal");
	var personalList1=$("#taskList-personal1");
	personalList.empty();
	personalList1.empty();
	var list=data.list;
	if(list.length <= 0){
		var s="<tr><td colspan=\"4\">暂无任务</td></tr>";
		var s1="<tr><td colspan=\"2\">暂无任务</td></tr>";
		personalList.append(s);
		personalList1.append(s1);
	}else{
		for(var i=0;i<list.length;i++){
			var item=list[i];
			var s="";
			s+="<tr bgcolor=\""+setColor(item.taskStatus)+"\" onclick=\"displayDetail("+item.assignId+",'PERSONALTASK')\">";
			s+="<td title=\""+item.title+"\">"+item.title+"</td>";
			s+="<td title=\""+item.assignDate+"\">"+item.assignDate+"</td>";
			s+="<td title=\""+item.createName+"\">"+item.createName+"</td>";
			s+="<td title=\""+getStatus(item.taskStatus)+"\">"+getStatus(item.taskStatus)+"</td>";
			s+="</tr>";
			personalList.append(s);
			var s1="";
			s1+="<tr bgcolor=\""+setColor(item.taskStatus)+"\" onclick=\"displayDetail("+item.assignId+",'PERSONALTASK')\">";
			
			s1+="<td title=\""+item.title+"\">"+item.title+"</td>";
			s1+="<td title=\""+item.assignDate+"\">"+item.assignDate+"</td>";
			s1+="</tr>";
			personalList1.append(s1);
		}
	}
	
	initPages(data.pageNo,data.allpages);
};

var initLessonTask = function(data){
	var type='${param.type}';
	if(!isEmpty(type)){
		$("#searchTaskType").val(type);
	}
	var taskList=$("#taskList");
	var taskList1=$("#taskList1");
	taskList.empty();
	taskList1.empty();
	var list=data.list;
	if(list.length <= 0){
		var s="<tr><td colspan=\"5\">暂无任务</td></tr>";
		var s1="<tr><td colspan=\"2\">暂无任务</td></tr>";
		taskList.append(s);
		taskList1.append(s1);
	}else{
		for(var i=0;i<list.length;i++){
			var item=list[i];
			var s="";
			var s1="";			
			if(item.type=="ASKINLESSON"){
				s+="<tr bgcolor=\"#D2F2DA\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
				s+="<td title=\""+getTaskType(item.type)+"\">"+getTaskType(item.type)+"</td>";
				s+="<td title=\""+item.title+"\">"+item.title+"</td>";
				s+="<td>-----</td>";
				s1+="<tr bgcolor=\"#D2F2DA\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
			}else{
				s+="<tr bgcolor=\""+setColor(item.taskStatus)+"\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
				s+="<td title=\""+getTaskType(item.type)+"\">"+getTaskType(item.type)+"</td>";
				s+="<td title=\""+item.title+"\">"+item.title+"</td>";
				s+="<td title=\""+item.deadline+"\">"+item.deadline+"</td>";
				s1+="<tr bgcolor=\""+setColor(item.taskStatus)+"\" onclick=\"displayDetail("+item.assignId+",'"+item.type+"')\">";
			}
			s+="<td title=\""+getSubmitStatus(item)+"\">"+getSubmitStatus(item)+"</td>";
			s+="<td title=\""+item.beginDate+"-"+item.endDate+"\">"+item.beginDate+"-"+item.endDate+"</td>"
			s+="</tr>";
			
			s1+="<td title=\""+item.title+"\">"+item.title+"</td>";
			s1+="<td title=\""+item.deadline+"\">"+item.deadline+"</td>";
			s1+="</tr>";
			taskList.append(s);
			taskList1.append(s1);
		}
	}
	
	initPages(data.pageNo,data.allpages);
};

var getSubmitStatus = function(task){
	if(task.type == "ASKINLESSON"){
		return "--";
	}else if(task.type == "TESTINLESSON"|| task.type == "HOMEWORK" || task.type == "LABTEST"){
		return getStatus(task.taskStatus);
	}else{
		return "error";
	}
};
var setColor = function(status){
	if(status=="UNCOMMITTED"){
		return "#F2CECE";
	}else if(status=="COMMITTED"){
		return "#F4EED6";
	}else if(status=="HAVEREAD"){
		return "#D2F2DA";
	}else{
		return ;
	}
};
var getStatus  = function(status){
	if(status=="UNCOMMITTED"){
		return "未提交";
	}else if(status=="COMMITTED"){
		return "已提交";
	}else if(status=="HAVEREAD"){
		return "已批改";
	}else{
		return "服务器出错";
	}
};

var getTaskType = function(type){
	if(type=="ASKINLESSON"){
		return "课堂提问";
	}else if(type=="TESTINLESSON"){
		return "当堂测试";
	}else if(type=="HOMEWORK"){
		return "课后作业";
	}else if(type=="LABTEST"){
		return "实验任务";
	}else if(type=="PERSONALTASK"){
		return "个人任务";
	}else{
		return "其他";
	}
};



var isEmpty=function(s){
	if(s==null||s=="" || s==undefined){
		return true;
	}
	return false;
};
</script>
</html>